<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:bi="http://java.sun.com/jsf/composite/bill"
      xmlns:pa="http://java.sun.com/jsf/composite/paymentMethod">

    <h:body>
        <ui:composition template="/resources/template/template.xhtml">

            <ui:define name="content">
                <h:form>
                    <p:panel header="Reprint"  rendered="#{!billController.printPreview}">
                        <f:facet name="header" >
                            <h:outputLabel value="Paymetn For OPD Bill" ></h:outputLabel>
                        </f:facet>

                        <p:panel>
                            <p:panelGrid columns="2" style="width: 100%;">
                                <p:panel header="Patient Detail">
                                    <p:panelGrid columns="2">
                                        <h:outputLabel value="Patient ​Name:" ></h:outputLabel>
                                        <h:outputLabel value="#{billSearch.bill.patient.person.nameWithTitle }" ></h:outputLabel>
                                        <h:outputLabel value="Age" />
                                        <h:outputLabel value="#{billSearch.bill.patient.age}"  />
                                        <h:outputLabel value="Sex" >
                                        </h:outputLabel>
                                        <h:outputLabel value="#{billSearch.bill.patient.person.sex}" >
                                        </h:outputLabel>
                                        <h:outputLabel value="Phone" >
                                        </h:outputLabel>
                                        <h:outputLabel value="#{billSearch.bill.patient.person.phone}" >
                                        </h:outputLabel>
                                    </p:panelGrid>
                                </p:panel>
                                <p:panel header="Bill Detail">
                                    <p:panelGrid columns="2">
                                        <h:outputLabel value="Bill No :" ></h:outputLabel>
                                        <h:outputLabel value="#{billSearch.bill.deptId}" >
                                        </h:outputLabel>
                                        <h:outputLabel value="Payment Type : " ></h:outputLabel>
                                        <h:outputLabel value="#{billSearch.bill.paymentMethod}" >
                                        </h:outputLabel>

                                        <h:outputLabel value="Total :" ></h:outputLabel>
                                        <h:outputLabel value="#{billSearch.bill.total}" >
                                            <f:convertNumber pattern="#,##0.00" ></f:convertNumber>
                                        </h:outputLabel>

                                        <h:outputLabel value=" Total Previous Settlements :" ></h:outputLabel>
                                        <h:outputLabel value="#{billSearch.bill.total - billSearch.bill.balance}" >
                                            <f:convertNumber pattern="#,##0.00" ></f:convertNumber>
                                        </h:outputLabel>

                                        <h:outputLabel value="Due Amount :" ></h:outputLabel>
                                        <h:outputLabel value="#{billSearch.bill.balance}" style="color: red;" >
                                            <f:convertNumber pattern="#,##0.00" ></f:convertNumber>
                                        </h:outputLabel>
                                    </p:panelGrid>
                                </p:panel>
                            </p:panelGrid>
                            <p:panel header="Bill Item Detail">
                                <p:dataTable rowIndexVar="rowIndex"
                                             editable="true" value="#{billSearch.billFees2}" var="bip" >
                                    <p:ajax event="rowEdit" listener="#{billSearch.onEdit}" />  
                                    <p:ajax event="rowEditCancel" listener="#{billSearch.onEdit}" />  
                                    <p:column>
                                        <f:facet name="header">No</f:facet>
                                        <h:outputLabel value="#{rowIndex+1}"/>
                                    </p:column>
                                    <p:column>
                                        <f:facet name="header">Item</f:facet>
                                        <h:outputLabel value="#{bip.billItem.item.name}"/>
                                    </p:column>
                                    <p:column>
                                        <f:facet name="header">Fee</f:facet>
                                        <h:outputLabel value="#{bip.feeValue}"/>
                                    </p:column>  
                                    <p:column>
                                        <f:facet name="header">Fee Name</f:facet>
                                        <h:outputLabel value="#{bip.fee.name}"/>
                                    </p:column> 
                                    <p:column>
                                        <f:facet name="header">Speciality</f:facet>
                                        <h:outputLabel value="#{bip.fee.speciality.name}"/>
                                    </p:column> 
                                    <p:column headerText="Payee">
                                        <p:cellEditor>  
                                            <f:facet name="output"> 
                                                <h:outputLabel value="#{bip.staff.person.name}"  ></h:outputLabel>
                                            </f:facet>  
                                            <f:facet name="input">  
                                                <p:selectOneMenu value="#{bip.staff}" rendered="#{bip.fee.speciality!=null}" disabled="#{bip.paidValue!=0 or !webUserController.hasPrivilege('ChangeProfessionalFee')}" >
                                                    <f:selectItem itemLabel="Select Staff" />
                                                    <f:selectItems  value="#{staffController.getSpecialityStaff(bip.fee.speciality)}" var="bifs" itemLabel="#{bifs.person.name}" itemValue="#{bifs}" />
                                                </p:selectOneMenu>
                                            </f:facet>  
                                        </p:cellEditor>  

                                    </p:column>
                                    <p:column style="width:6%">  
                                        <p:rowEditor > 
                                        </p:rowEditor>
                                    </p:column>  
                                </p:dataTable>
                            </p:panel>
                            <p:panel>
                                <p:panelGrid columns="2" >

                                    <p:outputLabel value="Payment Methord" />
                                    <p:panelGrid columns="5" >
                                        <h:panelGrid columns="1">                                
                                            <p:selectOneMenu   id="pay" value="#{billController.paymentMethod}">     
                                                <f:selectItems value="#{enumController.paymentMethods}"  />
                                                <p:ajax process="@this" 
                                                        update="creditCard cheque slip"
                                                        event="change"
                                                        listener="#{billController.changeListener()}"/>
                                            </p:selectOneMenu>
                                        </h:panelGrid>
                                        <p:inputText value="#{billController.comment}" id="comment"/>
                                        <p:watermark value="Comment" for="comment"/>

                                        <h:panelGroup id="creditCard" style="display: #{billController.paymentMethod ne 'Card' ? 'none' : 'block'} ; ">
                                            <pa:creditCard paymentMethodData="#{billController.paymentMethodData}"/>
                                        </h:panelGroup>

                                        <h:panelGroup id="cheque" style="display: #{billController.paymentMethod ne 'Cheque' ? 'none' : 'block'} ; " >
                                            <pa:cheque paymentMethodData="#{billController.paymentMethodData}"/>
                                        </h:panelGroup>

                                        <h:panelGroup id="slip" style="display: #{billController.paymentMethod ne 'Slip' ? 'none' : 'block'} ;">
                                            <pa:slip paymentMethodData="#{billController.paymentMethodData}"/>
                                        </h:panelGroup>
                                    </p:panelGrid>
                                    <p:outputLabel value="Paying Ammount" />
                                    <p:inputText value="#{billController.opdPaymentCredit}" />
                                    <p:commandButton value="Pay" action="#{billController.saveBillOPDCredit}" ajax="false" />
                                </p:panelGrid>
                            </p:panel>
                        </p:panel>
                    </p:panel>




                    <h:panelGroup  rendered="#{billController.printPreview}">


                        <h:panelGroup rendered="#{sessionController.loggedPreference.opdBillPaperType eq 'FiveFivePaper'}">
                            <div id="centrewrapper">
                                <div id="centrecell">
                                    <div class="centrecontent">
                                        <p:commandButton value="Print" ajax="false" action="#" onclick="onSubmitButton();" >
                                            <p:printer target="gpBillPreview" ></p:printer>
                                        </p:commandButton>
                                        <p:commandButton value="New Bill" ajax="false" action="/opd_search_bill_to_pay" actionListener="#{billController.clear()}" onclick="onSubmitButton();" >
                                        </p:commandButton>


                                        <h:outputStylesheet library="css" name="printing.css"></h:outputStylesheet>

                                        <div style="border: 1px solid;" >
                                            <h:panelGroup id="gpBillPreview" >

                                                <div  class="fiveinchbill">
                                                    <div class="heading" >
                                                        <p:outputLabel value="Opd Payment Bill" />
                                                    </div>

                                                    <div  class="receiptno">
                                                        <h:outputLabel value="#{billController.opdBill.insId}"  
                                                                       /> 

                                                    </div>

                                                    <div  class="billdate">
                                                        <h:outputLabel value="#{billController.opdBill.billDate}"
                                                                       >
                                                            <f:convertDateTime pattern="dd/MM/yy"/>
                                                        </h:outputLabel>
                                                    </div>

                                                    <div class="payment">
                                                        <h:outputLabel value="#{billController.opdBill.paymentMethod}"/>
                                                    </div>

                                                    <div class="billtime">
                                                        <h:outputLabel value="#{billController.opdBill.billTime}" >
                                                            <f:convertDateTime pattern="hh mm a"/>
                                                        </h:outputLabel>

                                                    </div>

                                                    <h:outputLabel value="#{billController.opdBill.referenceBill.patient.person.nameWithTitle}" styleClass="ptname" />

                                                    <h:outputLabel value="#{billController.opdBill.referenceBill.patient.person.phone}" styleClass="phone" />


                                                    <div class="items" >
                                                        <h:dataTable value="#{billController.opdBill.referenceBill.billItems}" var="bip"   >
                                                            <h:column >
                                                                <h:outputLabel rendered="#{bip.item.department.id eq bill.toDepartment.id}" value="#{bip.item.printName}" style="margin: 4px; font-size: 11px!important;" >
                                                                </h:outputLabel>
                                                                <h:panelGroup rendered="#{bip.item.department.id eq bill.toDepartment.id and bip.billSession ne null }"  >
                                                                    <br/>
                                                                    <h:panelGroup rendered="#{bip.item.sessionNumberType eq null}">
                                                                        <h:outputLabel value="Session No . " ></h:outputLabel>
                                                                        <h:outputLabel value="#{bip.billSession.serialNo}" style="margin: 4px; font-size: 11px!important;" >
                                                                        </h:outputLabel>
                                                                    </h:panelGroup>
                                                                </h:panelGroup>
                                                            </h:column>
                                                        </h:dataTable>
                                                    </div>

                                                    <div class="rates"  >
                                                        <h:dataTable value="#{billController.opdBill.referenceBill.billItems}" var="bip1"  >
                                                            <h:column >
                                                                <h:outputLabel  rendered="#{bip1.bill.id eq bill.id}"  value="#{bip1.grossValue}"  style="margin: 4px; font-size: 11px!important;" >
                                                                    <f:convertNumber pattern="#,#00.00" />
                                                                </h:outputLabel>
                                                            </h:column>
                                                        </h:dataTable>
                                                    </div>


                                                    <!--                                                <div class="items" >
                                                                                                        <h:outputLabel value="Paid Amount">
                                                    
                                                                                                        </h:outputLabel>
                                                                                                    </div>
                                                    
                                                                                                    <div class="rates" >
                                                    
                                                                                                        <h:outputLabel value="#{billController.opdBill.paidAmount}"  style="margin: 4px;" >
                                                                                                            <f:convertNumber pattern="#,#00.00" />
                                                                                                        </h:outputLabel>
                                                    
                                                                                                    </div>-->

                                                    <div class="totals">
                                                        <table>
                                                            <tr>
                                                                <td>
                                                                    <br/>
                                                                    <br/>
                                                                </td>
                                                                <td>
                                                                    <br/>
                                                                    <br/>
                                                                </td>
                                                            </tr>

                                                            <tr>
                                                                <td style="text-align: left; min-width: 3cm;">
                                                                    <h:outputLabel value="Total" style="  text-align: right!important;  font-size: 15px!important;   "/>
                                                                </td>
                                                                <td style="text-align: right!important; ">
                                                                    <h:outputLabel value="#{billController.opdBill.referenceBill.total}"  style=" font-weight: bold ; text-align: right!important; font-size: 15px!important;    ">
                                                                        <f:convertNumber pattern="#,#00.00" />
                                                                    </h:outputLabel>
                                                                </td>
                                                            </tr>

                                                            <tr>
                                                                <td style="text-align: left; min-width: 3cm;">
                                                                    <h:outputLabel value="Paying" style="  text-align: right!important;  font-size: 15px!important;   "/>
                                                                </td>
                                                                <td style="text-align: right!important; ">
                                                                    <h:outputLabel value="#{billController.opdBill.total}"  style=" font-weight: bold ; text-align: right!important; font-size: 15px!important;    ">
                                                                        <f:convertNumber pattern="#,#00.00" />
                                                                    </h:outputLabel>
                                                                </td>
                                                            </tr>


                                                            <h:panelGroup rendered="#{billController.opdBill.referenceBill.balance gt 1}" >
                                                                <tr>
                                                                    <td style="text-align: left; min-width: 3cm;">
                                                                        <h:outputLabel value="Paying" style="  text-align: right!important;  font-size: 15px!important;   "/>
                                                                    </td>
                                                                    <td style="text-align: right!important; ">
                                                                        <h:outputLabel value="#{billController.opdBill.referenceBill.balance}"  style=" font-weight: bold ; text-align: right!important; font-size: 15px!important;    ">
                                                                            <f:convertNumber pattern="#,#00.00" />
                                                                        </h:outputLabel>
                                                                    </td>
                                                                </tr>
                                                            </h:panelGroup>


                                                        </table>
                                                    </div>

                                                    <div class="cashier" >
                                                        <h:outputLabel value="Cashier : #{billController.opdBill.creater.code}"/>


                                                    </div>



                                                </div>



                                            </h:panelGroup>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </h:panelGroup>

                        <h:panelGroup rendered="#{sessionController.loggedPreference.opdBillPaperType eq 'PosPaper'}">

                            <div class="nonPrintBlock">
                                <p:commandButton value="Print" ajax="false" action="#"  >
                                    <p:printer target="gpPosBill" ></p:printer>
                                </p:commandButton>

                                <p:commandButton value="New Bill" ajax="false" action="/opd_search_bill_to_pay" actionListener="#{billController.clear()}" onclick="onSubmitButton();" >
                                </p:commandButton>

                            </div>
                            <h:panelGroup id="gpPosBill">
                                <bi:posOpdBill_bal bill="#{billController.opdBill}" duplicate="false"/>                        
                                <div></div>
                                <bi:posOpdBill_bal bill="#{billController.opdBill}" duplicate="false"/>
                            </h:panelGroup>

                        </h:panelGroup>
                    </h:panelGroup>


                </h:form>
            </ui:define>



        </ui:composition>

    </h:body>
</html>
